public class Hero {
    //经验值
    private int exp;
    //等级 默认1级
    private int grade = 1;
    //攻击力 默认500
    private int power = 500;
    //姓名
    private String hName;
    //构造方法
    public Hero() {}
    public Hero(String hName) {
        this.hName= hName;
    }
    //修改经验
    private void setExp(int exp) {
        this.exp += exp;
    }
    //获取经验
    public int getExp() {
        return exp;
    }

    //获取等级
    public int getGrade() {
        //每100经验升一级
        return this.exp/100;
    }
    //获取攻击力
    public int getPower() {
        return this.power;
    }
    //获取英雄名字
    public String gethName() {
        return this.hName;
    }
    //打怪兽的方法
    public void hit(Monster monster) {
        this.exp = monster.getLife();
        //打怪兽的次数
        int times = 0;
        while(monster.getLife() != 0) {
            //击打怪兽次数增加
            times++;
            //怪兽生命值减少
            monster.setLife(this.power);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(this.gethName() + "英雄第" + times + "次击打"
                    + monster.getmName() + "的怪兽，怪兽的生命值还剩"
                    + monster.getLife() + "生命");
            //打掉的怪兽生命值转化为英雄的经验
            this.setExp(this.getPower());
        }
        System.out.println("打完啦！！！\n英雄等级升到" + this.getGrade());
    }
}